package JUC;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author 豆包LU
 * @date 2023/5/22 22:37
 */
public class SharedDataExample {
    public static void main(String[] args) throws InterruptedException {
        ConcurrentHashMap<String, String> sharedData = new ConcurrentHashMap<String, String>();
        MyThread thread = new MyThread(sharedData);
        thread.start();
        thread.join();
//        sharedData.put("key", "value");
        System.out.println("sharedData in main thread: " + sharedData.get("key"));
    }
}

class MyThread extends Thread {
    ConcurrentHashMap<String, String> sharedData;
    public MyThread(ConcurrentHashMap<String, String> data) {
        this.sharedData = data;
    }
    public void run() {
        sharedData.put("key", "new value");
        System.out.println("sharedData in child thread: " + sharedData.get("key"));
    }
}

